import { Response } from 'express';

/**
 * 自动将 BigInt 转字符串，避免 JSON 报错
 */
export function safeJson(res: Response, data: any, message = 'OK', code = 0, status = 200) {
  const safe = JSON.parse(JSON.stringify(data, (_, v) =>
    typeof v === 'bigint' ? v.toString() : v
  ));
  res.status(status).json({ code, message, data: safe });
}

export function bigintToString(data: any) {
  return JSON.parse(JSON.stringify(data, (_, v) =>
    typeof v === 'bigint' ? v.toString() : v
  ));
}
